﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DamageCalculator.SubForms
{
    public partial class SettingsForm : Form
    {
        bool ClosedWithButton = false;

        public SettingsForm()
        {
            InitializeComponent();
            this.SetValues();
        }

        private void SetValues()
        {
            this.Txt_TimeEncounters.Text = Properties.Settings.Default.TimeBetweenEncounters.ToString();
            this.Chk_ShowChart.Checked = Properties.Settings.Default.OverlayShowChart;
            this.Chk_ShowText.Checked = Properties.Settings.Default.OverlayShowText;
            this.Btn_TxtColor.BackColor = Properties.Settings.Default.OverlayTextColor;
            this.Btn_TxtBackgroundcolor.BackColor = Properties.Settings.Default.OverlayBackgroundColor;
            this.Txt_MinWidth.Text = Properties.Settings.Default.OverlayMinimumWidth.ToString();
            this.Txt_ChartHeight.Text = Properties.Settings.Default.OverlayChartHeight.ToString();
            this.Btn_Font.Font = Properties.Settings.Default.OverlayFont;
            this.Chk_MYDPS.Checked = Properties.Settings.Default.OverlayDisplayMyDPS;
            this.Chk_ShowXP.Checked = Properties.Settings.Default.OverlayDisplayXP;
            this.Chk_TeamDPS.Checked = Properties.Settings.Default.OverlayDisplayTeamDPS;
            this.Chk_ShowHPS.Checked = Properties.Settings.Default.OverlayDisplayMyHPS;
            this.Chk_AutoCopy.Checked = Properties.Settings.Default.AutoCopyResults;
        }

        private void SettingsForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!ClosedWithButton)
                e.Cancel = true;
        }

        private void Btn_TxtColor_Click(object sender, EventArgs e)
        {
            this.ColorDialog.Color = this.Btn_TxtColor.BackColor;
            DialogResult R = this.ColorDialog.ShowDialog();
            if (R == System.Windows.Forms.DialogResult.OK)
                this.Btn_TxtColor.BackColor = this.ColorDialog.Color;
        }

        private void Btn_TxtBackgroundcolor_Click(object sender, EventArgs e)
        {
            this.ColorDialog.Color = this.Btn_TxtBackgroundcolor.BackColor;
            DialogResult R = this.ColorDialog.ShowDialog();
            if (R == System.Windows.Forms.DialogResult.OK)
                this.Btn_TxtBackgroundcolor.BackColor = this.ColorDialog.Color;
        }

        private void Btn_Font_Click(object sender, EventArgs e)
        {
            this.FontDialog.Font = this.Btn_Font.Font;
            this.FontDialog.FontMustExist = true;
            DialogResult R = this.FontDialog.ShowDialog();
            if (R == System.Windows.Forms.DialogResult.OK)
                this.Btn_Font.Font = this.FontDialog.Font;
        }

        private void Btn_Cancel_Click(object sender, EventArgs e)
        {
            this.ClosedWithButton = true;
            this.Close();
        }

        private void Btn_OK_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.TimeBetweenEncounters = int.Parse(this.Txt_TimeEncounters.Text);
            Properties.Settings.Default.OverlayShowChart = this.Chk_ShowChart.Checked;
            Properties.Settings.Default.OverlayShowText = this.Chk_ShowText.Checked;
            Properties.Settings.Default.OverlayTextColor = this.Btn_TxtColor.BackColor;
            Properties.Settings.Default.OverlayBackgroundColor = this.Btn_TxtBackgroundcolor.BackColor;
            Properties.Settings.Default.OverlayMinimumWidth = int.Parse(this.Txt_MinWidth.Text);
            Properties.Settings.Default.OverlayChartHeight = int.Parse(this.Txt_ChartHeight.Text);
            Properties.Settings.Default.OverlayFont = this.Btn_Font.Font;
            Properties.Settings.Default.OverlayDisplayMyDPS = this.Chk_MYDPS.Checked;
            Properties.Settings.Default.OverlayDisplayXP = this.Chk_ShowXP.Checked;
            Properties.Settings.Default.OverlayDisplayTeamDPS = this.Chk_TeamDPS.Checked;
            Properties.Settings.Default.OverlayDisplayMyHPS = this.Chk_ShowHPS.Checked;
            Properties.Settings.Default.AutoCopyResults = this.Chk_AutoCopy.Checked;

            Properties.Settings.Default.Save();

            this.ClosedWithButton = true;

            this.Close();
        }
    }
}
